package ooday04;



public class Test {
    public static void main(String[] args) {
        Person[] ps = new Person[5];
        ps[0] = new Student("zhangsan",25,"LF","111"); //向上造型
        ps[1] = new Student("lisi",26,"JMS","222");
        ps[2] = new Teacher("wangwu",35,"SD",80000.0);
        ps[3] = new Teacher("zhaoliu",45,"SX",100000.0);
        ps[4] = new Doctor("sunqi",56,"LF","主任医师");
        for(int i=0;i<ps.length;i++){
            ps[i].sayHi();
        }

        //重写方法被调用时，看对象的类型
        Student zs = new Student("zhangsan",25,"LF","111");
        Person  p  = new Student("zhangsan",25,"LF","111");
        zs.sayHi();
        p.sayHi();
    }
}
class Person{
    String name;
    int age;
    String address;
    Person(String name,int age,String address){
        this.name = name;
        this.age = age;
        this.address = address;
    }
    void sayHi(){
        System.out.println("大家好，我叫"+name+"，今年"+age+"岁了，家住"+address);
    }
}
class Student extends Person{
    String stuId;
    Student(String name,int age,String address,String stuId){
        super(name,age,address);
        this.stuId = stuId;
    }
    void sayHi(){
        System.out.println("大家好，我叫"+name+"，今年"+age+"岁了，家住"+address+"，学号为:"+stuId);
        super.sayHi();
        this.stuId="3";
        super.name="ls";
    }
}
class Teacher extends Person{
    double salary;
    Teacher(String name,int age,String address,double salary){
        super(name,age,address);
        this.salary = salary;
    }
    void sayHi(){
        System.out.println("大家好，我叫"+name+"，今年"+age+"岁了，家住"+address+"，工资为:"+salary);
    }
}
class Doctor extends Person{
    String level;
    Doctor(String name,int age,String address,String level){
        super(name,age,address);
        this.level = level;
    }
}



























